<template>
  <div>
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a :class="['mui-control-item',item.id==0?'mui-active':'']" v-for="(item,index) in imgCategory" :key="index" @click="getImgList(item.id)">{{item.title}}</a>
        </div>
      </div>
    </div>

    <ul class="photo-list">
      <router-link v-for="(item,index) in imgList" :key="index" :to="'/home/photoinfo/'+index" tag="li">
        <img alt="" v-lazy="item">
        <div class="info">
          <div class="info-title">现代简约房间装修</div>
          <div class="info-body">当地时间8日清晨,乌克兰国际航空公司一架波音737客机在伊朗首都德黑兰的霍梅尼国际机场附近坠毁,机上人员无一生还。 8日晚间,伊朗坠机事故调查组公布乌克兰飞机坠毁的</div>
        </div>
      </router-link>
    </ul>

  </div>
</template>


<script>
import mui from "../../lib/mui/js/mui.min.js"
import { Toast } from "mint-ui"

export default {
  data() {
    return {
      imgCategory:[],
      imgList:''
    };
  },
  created(){
    this.getCategory();
  },
  mounted() {
    //当组件中的dom结构被渲染好并放到页面中后，会执行这个钩子函数
    //如果要操作元素了，最好在mounted里面，因为这里的dom是最新的
    //初始化滑动控件
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //减速系数：系数越大滚动速度越慢
    }),
    this.getImgList(0)
  },
  methods:{
    getCategory(){
      this.$http.get("/src/data/imgShare/imgCategory.json").then(result => {
        if(result.status === 200){
          this.imgCategory = result.body.message;
          this.imgCategory.unshift({"id":0,"title":"全部"})
        }else{
          Toast("获取图片分类信息失败！");
        }
      })
    },
    getImgList(id){
      this.imgList = [];
      this.$http.get("/src/data/imgShare/imgList.json").then(result =>{
        if(result.status === 200){
          var data = result.body;
          if(id == 0){
            for(var key in data){
              data[key].map((c) => {this.imgList.push(c)})
            }
            return;
          }else{
            this.imgList = data[id];
          }
        }else{
          Toast("获取图片信息失败！");
        }
      })
    }
  }
};
</script>


<style lang="scss" scoped>
* {
  touch-action: pan-y;
}
.photo-list{
  list-style-type: none;
  margin: 0;
  padding: 10px;
  padding-bottom:0;
  li{
    background-color: #ccc;
    text-align: center;
    margin-bottom: 10px;
    box-shadow: 0 0 9px #999;
    position: relative;
    img{
      width:100%;
      vertical-align: middle;
    }
  }
  img[lazy="loading"]{
    width:40px;
    height:300px;
    margin:auto;
  }
  
  .info{
    color: white;
    text-align: left;
    position: absolute;
    bottom: 0;
    background-color: rgba(0,0,0,0.4);
    max-height:84px;
    .info-title{
      font-size: 14px;
      font-weight: 800;
    }
    .info-body{
      font-size: 13px;
    }
  }
}
</style>